<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<%@taglib prefix="fkyuan" uri="http://github.com/fkyuan/tags/fkyuan-functions" %>
<%@taglib prefix="pagetag" uri="http://github.com/fkyuan/tags/pagetag" %>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>
<html>
<head>
    <title></title>
    <%@include file="/WEB-INF/pages/common/basic-styles.jspf" %>
</head>
<body>

<c:if test="${not empty msg}">
<div class="alert alert-block alert-success"">
	<button type="button" class="close" data-dismiss="alert">
		<i class="icon-remove"></i>
	</button>
	<p>
		<strong>
			<i class="icon-ok"></i>
		</strong>
		${msg}
	</p>
</div>
</c:if>

<div class="operate panel panel-default">
	<div class="panel-body">
		<form:form class="form-horizontal" method="get" commandName="user">
			<label for="username"> 用户名 </label>
			<input type="text" id="username" name="username" placeholder="请输入内容..." value="${username}"/>
			<form:button class="btn btn-purple btn-sm">
				查询
				<i class="icon-search icon-on-right bigger-110"></i>
			</form:button>
		</form:form>		
	</div>
</div>

<div class="operate panel panel-default" style="height:65px;">
	<div class="panel-body">
		<shiro:hasPermission name="user:create">
			<button class="btn btn-sm btn-primary add">新增</button>
		</shiro:hasPermission>
		<shiro:hasPermission name="user:update">
            <button class="btn btn-sm btn-primary update">修改</button>
			<button class="btn btn-sm btn-primary changePassword">修改密码</button>
			<button class="btn btn-sm btn-primary enable">启用</button>
			<button class="btn btn-sm btn-primary disable">停用</button>
        </shiro:hasPermission>
		<shiro:hasPermission name="user:delete">
			<button class="btn btn-sm btn-primary delete">删除</button>
		</shiro:hasPermission>
	</div>	
</div>		

<div class="table-responsive">
	<form id="listForm" method="post">
	<input type="hidden" id="state" name="state">
	<table class="table table-striped table-bordered table-hover">
		<thead>
			<tr>
				<th class="center" width="5%">
					<label>
						<input type="checkbox" class="ace"/>
						<span class="lbl"></span>
					</label>
				</th>
				<th>用户名</th>
				<th>所属组织</th>
				<th>角色列表</th>
			</tr>
		</thead>

		<tbody>
			<c:forEach items="${pageInfo.list}" var="user">
			<tr>
				<td class="center">
					<label>
						<input type="checkbox" class="ace" name="ids" value="${user.id}"/>
						<span class="lbl"></span>
					</label>
				</td>
				<td>${user.username}</td>
				<td>${fkyuan:organizationName(user.organizationId)}</td>
				<td>${fkyuan:roleNames(user.roles)}</td>
			</tr>
			</c:forEach>
		</tbody>
	</table>
	</form>
</div><!-- /.table-responsive -->

<pagetag:pagination totalSum="${pageInfo.total}" pageSize="${pageInfo.pageSize}"></pagetag:pagination>

<%@include file="/WEB-INF/pages/common/basic-scripts.jspf" %>  
<!-- inline scripts related to this page -->
<script type="text/javascript">
	$(function() {
		$('table th input:checkbox').on('click' , function(){
			$("input[name='ids']").prop("checked", this.checked);
		});				
		$('.alert-success').delay(3000).hide(0);
	
		$('.add').on('click', function() {
			location.href = '${ctx}/manage/system/user/create';
		});
		
		$('.update').on('click', function() {
			var num = getCheckedNumByName("ids");
			if (num < 1) {
				defaultAlert("请选择要修改的信息");
				return false;
			}
			if (num > 1) {
				defaultAlert("不能批量修改，请重新选择");
				return false;
			}				
			var id = getCheckedValueByName("ids"); 
			location.href = '${ctx}/manage/system/user/update/' + id;
		});
		
		$('.changePassword').on('click', function() {
			var num = getCheckedNumByName("ids");
			if (num < 1) {
				defaultAlert("请选择要修改的信息");
				return false;
			}
			if (num > 1) {
				defaultAlert("不能批量修改，请重新选择");
				return false;
			}
			var id = getCheckedValueByName("ids"); 
			location.href = '${ctx}/manage/system/user/changePassword/' + id;
		});
		
		$('.enable').on('click', function() {
			var ischeck = getCheckedByName("ids");
			if (!ischeck) {
				defaultAlert("请选择要启用的用户");
				return;
			}	
			$("#state").val(0);
			loading();
			$("#listForm").attr("action", "${ctx}/manage/system/user/updateState");
			$("#listForm").submit();
		});
		
		$('.disable').on('click', function() {
			var ischeck = getCheckedByName("ids");
			if (!ischeck) {
				defaultAlert("请选择要停用的用户");
				return;
			}	
			$("#state").val(1);
			loading();
			$("#listForm").attr("action", "${ctx}/manage/system/user/updateState");
			$("#listForm").submit();
		});
		
		$('.delete').on('click', function() {
			var ischeck = getCheckedByName("ids");
			if (!ischeck) {
				defaultAlert("请选择要删除的信息");
				return;
			}				
			defaultConfirm("确定要删除选择的信息吗?", function(result) {
				if (result) {
					loading();
					$("#listForm").attr("action", "${ctx}/manage/system/user/delete");
					$("#listForm").submit();
				}
	        });
		});
	});
</script>
</body>
</html>